/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.eleric.rememome.adapter.impl;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.eleric.rememome.memo.Memo;
import com.eleric.rememome.priority.PriorityColor;
import com.eleric.rememome.priority.PriorityColorFactory;
import com.eleric.rememome.priority.impl.PriorityColorPriorityTypeImpl;
import com.eleric.rememome.type.PriorityType;
import java.util.List;

/**
 *
 * @author mwaldman
 */
public class MemoListAdapter extends ArrayAdapter<Memo>
{

    protected int maxPriority;
    final protected float colorMax = 255;
    protected PriorityColor priorityColor;

    public MemoListAdapter(Context context, int textViewResourceId, List<Memo> objects)
    {
        super(context, textViewResourceId, objects);
        this.maxPriority = maxPriority;
        priorityColor = PriorityColorFactory.createPriorityColor();
    }

    public MemoListAdapter(Context context, int textViewResourceId, Memo[] objects)
    {
        super(context, textViewResourceId, objects);
        this.maxPriority = maxPriority;
        priorityColor = PriorityColorFactory.createPriorityColor();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View v = super.getView(position, convertView, parent);
        if (v instanceof TextView)
        {
            TextView tv;
            Memo memo;
            int color;
            tv = (TextView) v;
            memo = getItem(position);
            color = getColor(memo);
            tv.setTextColor(color);
        }
        return v;
    }

    protected int getColor(Memo memo)
    {
        int priority;
        int color;
        priority = memo.getPriority();
        color = priorityColor.getColor(priority);
        return color;
    }

}
